public class test02 {
    class Solution {
        public int maxSubArray(int[] nums) {
            int sum = 0;
            int res = Integer.MIN_VALUE;
            int left = 0,right = 0;
            while(right<nums.length){
                sum += nums[right];
                res = Math.max(res,sum);
                while(sum<0){
                    sum -= nums[left];
                    left++;
                }
                right++;
            }
            return res;
        }
    }
}
